package cn.etynit.org.controller;

import cn.etynit.basic.anno.PreAuthorize;
import cn.etynit.org.service.IShopAuditLogService;
import cn.etynit.org.domain.ShopAuditLog;
import cn.etynit.org.query.ShopAuditLogQuery;
import cn.etynit.basic.util.AjaxResult;
import cn.etynit.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shopAuditLog")
//@PreAuthorize
public class ShopAuditLogController {
    @Autowired
    public IShopAuditLogService shopAuditLogService;


    /**
     * 保存和修改公用的
     * @param shopAuditLog  传递的实体
     * @return AjaxResult转换结果
     */
    @PutMapping
//    @PreAuthorize(name = "添加或修改店铺",sn = "department:addOrUpdate")
    public AjaxResult addOrUpdate(@RequestBody ShopAuditLog shopAuditLog){
        try {
            if( shopAuditLog.getId()!=null)
                shopAuditLogService.update(shopAuditLog);
            else
                shopAuditLogService.add(shopAuditLog);
            return AjaxResult.me().success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg("保存对象失败！"+e.getMessage());
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
//    @PreAuthorize(name = "删除店铺",sn = "department:delete")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            shopAuditLogService.delete(id);
            return AjaxResult.me().success();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
//    @PreAuthorize(name = "查询单个店铺",sn = "department:get")
    public ShopAuditLog get(@PathVariable("id")Long id)
    {
        return shopAuditLogService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
//    @PreAuthorize(name = "查询店铺",sn = "department:List")
    public List<ShopAuditLog> list(){

        return shopAuditLogService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
//    @PreAuthorize(name = "分页查询店铺",sn = "department:json")
    public PageList<ShopAuditLog> json(@RequestBody ShopAuditLogQuery query)
    {
        return shopAuditLogService.queryByPage(query);
    }

    // 查询日志
    @PostMapping("/findLog")
//    @PreAuthorize(name = "查询店铺日志",sn = "department:findByLog")
    public List<ShopAuditLog> findByLog(@RequestBody Long id){
        return shopAuditLogService.findByLog(id);
    }
}
